package com.zlyx.easy.web.generate;

import java.util.Map;

import com.zlyx.easy.core.tool.EasyBuffer;
import com.zlyx.easy.core.tool.FormatTool;
import com.zlyx.easy.core.utils.LogUtils;
import com.zlyx.easy.core.utils.ObjectUtils;
import com.zlyx.easy.core.utils.SpringUtils;
import com.zlyx.easy.database.annotations.TableBean;
import com.zlyx.easy.web.generate.annotations.EasyGenerater;
import com.zlyx.easy.web.generate.core.AbstractGenerator;
import com.zlyx.easy.web.generate.model.ModuleInfo;

/**
 * 
 * @Auth 赵光
 * @Describle
 * @Date 2019年1月22日
 */
@EasyGenerater(value = "easyGenerate", isGenerate = false, todo = { "" })
public class EasyGenerate extends AbstractGenerator{

	public void excute(ModuleInfo info) {
		Map<String, Object> tableBeans = SpringUtils.getBeanswithAnnotation(TableBean.class);
		this.author = info.getAuth();
		if(ObjectUtils.isEmpty(this.author)) {
			this.author = "easy-web 1316851612@qq.com";
		}
		this.basePath = info.getPath();
		if(ObjectUtils.isEmpty(this.basePath)) {
			this.basePath = "D://modules";
		}
		String entityTable = null;
		for(int i = 0; i < info.getNames().size(); i++) {
		    entityTable = info.getTables().get(i);
		    if(ObjectUtils.isNotEmpty(entityTable)) {
		    	 this.tableName = entityTable;
		    	 this.entityName = info.getNames().get(i);
		    	 if(ObjectUtils.isEmpty(this.entityName)) {
		    		 this.entityName = FormatTool.underline2Camel(entityTable);
				 }
		    	 this.packageName = info.getPaths().get(i);
		    	 if(ObjectUtils.isEmpty(this.packageName)) {
		    		 this.packageName = this.entityName.toLowerCase();
				 }
		    	 run(tableBeans);
		    }else {
		    	LogUtils.warn(EasyBuffer.wrapper("第",i,"个业务线的数据表为空！"));
		    }
		}
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		this.packageName = "com.zlyx";
		this.entityName = "Auth";
		this.tableName = "swh_auth";
	}
}
